home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / mdxfs.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  5KB  |  250 lines

  1. #include    "multix.h"
  2. #include    <stdio.h>
  3. #include    <stdlib.h>
  4. #include    <string.h>
  5. #include    <time.h>
  6.  
  7.  
  8. #include    "appl.h"
  9. TMdxProcId    MyId;
  10.  
  11. void    ApplGetFileReqReceived(
  12. TMdxSRMsgInfo  *MsgInfo
  13. )
  14. {
  15.     TFileTransferInfo    FileInfo;
  16.     TMdxMsg *Msg;
  17.  
  18.     MdxMsgRead(MsgInfo->Received.Msg,(UInt8Ptr)&FileInfo,sizeof(FileInfo));
  19.  
  20.     Msg =    MdxMsgNewFile(    FileInfo.SrcFileName,
  21.                                 (UInt8Ptr)&FileInfo,sizeof(FileInfo));
  22.  
  23.     if ( (Msg) == (void *)0 )
  24.     {
  25.         MdxReply(MsgInfo,ApplErrFileNotFound);
  26.     } else
  27.     {
  28.         MdxReplyWithMsg(MsgInfo,    /*    Original Msg    */
  29.                         MdErrNoError,            /*    No Error Reply    */
  30.                         Msg,                    /*    Msg                */
  31.                         MsgInfo->Received.MsgCode,
  32.                         MsgInfo->Received.MsgPri,    /*    Lowest Priority    */
  33.                         0,                            /*    Send Attributes    */
  34.                         0,                            /*    No ReqSeq        */
  35.                         0);
  36.     }
  37. }
  38.  
  39.  
  40. void    ApplPutFileReqReceived(
  41. TMdxSRMsgInfo  *MsgInfo
  42. )
  43. {
  44.     TFileTransferInfo    FileInfo;
  45.     FILE    *File;
  46.  
  47.  
  48.     MdxMsgRead(MsgInfo->Received.Msg,(UInt8Ptr)&FileInfo,sizeof(FileInfo));
  49.     if (    FileInfo.ReplaceFile    ==    True    )
  50.     {
  51.         File    =    fopen(FileInfo.TgtFileName,"wb");
  52.     } else
  53.     {
  54.         File    =    fopen(FileInfo.TgtFileName,"r");
  55.         if ( (File) != (void *)0 )
  56.         {
  57.             fclose(File);
  58.             MdxReply(MsgInfo,ApplErrFileExists);
  59.             return;
  60.         } else
  61.         {
  62.             File    =    fopen(FileInfo.TgtFileName,"wb");
  63.         }
  64.     }
  65.     if ( (File) == (void *)0 )
  66.     {
  67.         MdxReply(MsgInfo,ApplErrCreateFileError);
  68.     } else
  69.     {
  70.         TBufSize    CountRead;
  71.         UInt8        Buf[500];
  72.  
  73.  
  74.         while (    (CountRead    =    MdxMsgRead(    MsgInfo->Received.Msg,
  75.                                                 Buf,
  76.                                                 sizeof(Buf)
  77.                                                 )    )    >    0    )
  78.         {
  79.             if (    fwrite(Buf,1,CountRead,File)    !=    CountRead    )
  80.             {
  81.                 fclose(File);
  82.                 remove(FileInfo.TgtFileName);
  83.                 MdxReply(MsgInfo,ApplErrWriteFileError);
  84.                 return;
  85.             }
  86.         }
  87.         fclose(File);
  88.         MdxReply(MsgInfo,MdErrNoError);
  89.     }
  90. }
  91.  
  92.  
  93. void    ApplNewMsgReceived(
  94. TMdxEvent    *Event
  95. )
  96. {
  97.     TMdxSRMsgInfo    *MsgInfo;
  98.  
  99.     /*
  100.     "Event->Data"    holds the information abount the new message.
  101.     */
  102.  
  103.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  104.  
  105.  
  106.     /*    First    thing is to check MsgCode of the new message    */
  107.  
  108.     switch(MsgInfo->Received.MsgCode)
  109.     {
  110.         case    ApplPutFileMsgCode    :
  111.         {
  112.             ApplPutFileReqReceived(MsgInfo);
  113.         }
  114.         break;
  115.         case    ApplGetFileMsgCode    :
  116.         {
  117.             ApplGetFileReqReceived(MsgInfo);
  118.         }
  119.         break;
  120.         default                     :    break;
  121.     }
  122. }
  123.  
  124.  
  125. void    ApplCallReqReceived(
  126. TMdxEvent    *Event
  127. )
  128. {
  129.     /*
  130.     Event->ProcId    -    Holds the calling process id.
  131.     Event->Data        -    Holds the password used.
  132.     */
  133.  
  134.     MdxAcceptProcess(Event->ProcId,(void *)0);
  135. }
  136.  
  137.  
  138. void    ApplInitReceived(void)
  139. {
  140.     /*
  141.     You may choose to use onw or more links of the types specified.
  142.     Un comment the relevent "MdxOpenLink()".
  143.  
  144.     You may change the parameters for the links.
  145.     */
  146.  
  147.  
  148.     TMdxLinkParams    LinkParams;
  149.     memset(&LinkParams,0,sizeof(LinkParams));
  150.     strcpy(LinkParams.LinkName.Byte,"com2");
  151.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  152.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  153.     LinkParams.ConnectTimeout        =    0x7fffffff;
  154.     LinkParams.MaxConnectRetries    =    -1;
  155.     LinkParams.ConnectRetriesDelay    =    200;
  156.     LinkParams.LinkBaud             =    19200;
  157.     LinkParams.UseDlcFraming        =    True;
  158.     LinkParams.ImAliveInterval        =    400l;
  159.     LinkParams.MaxPollRetries        =    2;
  160.     LinkParams.L1MaxSendSize        =    256;
  161.     /*
  162.     MdxOpenLink(&LinkParams);
  163.     */
  164.     memset(&LinkParams,0,sizeof(LinkParams));
  165.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  166.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  167.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  168.     LinkParams.ConnectTimeout        =    1000;
  169.     LinkParams.MaxConnectRetries    =    -1;
  170.     LinkParams.ConnectRetriesDelay    =    200;
  171.     LinkParams.UseDlcFraming        =    True;
  172.     LinkParams.MaxPollRetries        =    10;
  173.     LinkParams.L1MaxSendSize        =    500;
  174.     /*
  175.     MdxOpenLink(&LinkParams);
  176.     */
  177.  
  178.     memset(&LinkParams,0,sizeof(LinkParams));
  179.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  180.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  181.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  182.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  183.     LinkParams.ConnectRetriesDelay    =    300l;
  184.     LinkParams.L1MaxSendSize        =    1024;
  185.     LinkParams.MaxConnectRetries    =    -1l;
  186.     /*
  187.     MdxOpenLink(&LinkParams);
  188.     */
  189. }
  190.  
  191.  
  192. void    cdecl    ApplEventHandler(
  193. TMdxEvent    *Event
  194. )
  195. {
  196.     switch(Event->Code)
  197.     {
  198.         case    MdxEventApplInit                :
  199.         {
  200.             ApplInitReceived();
  201.         }
  202.         break;
  203.         case    MdxEvCallReqReceived        :
  204.         {
  205.             ApplCallReqReceived(Event);
  206.         }
  207.         break;
  208.         case    MdxEvDataMsgReceived        :
  209.         {
  210.             ApplNewMsgReceived(Event);
  211.         }
  212.         break;
  213.         case    MdxStdInAvailable                :
  214.         {
  215.             exit(0);
  216.         }
  217.         break;
  218.         default                                 :    break;
  219.     }
  220. }
  221.  
  222.  
  223. Int cdecl    main(
  224. Int     Argc,
  225. Int8Ptr *Argv
  226. )
  227. {
  228.     if (    Argc    <    2    )
  229.     {
  230.         printf("Usage : mdxfs <Proccess Id>\n");
  231.         return(5);
  232.     }
  233.     MyId    =    (TMdxProcId)atol(Argv[1]);
  234.     if (    MyId    <=    0    )
  235.     {
  236.         printf("Node Id Should be between 1 - %ld\n",0x7fffffffl);
  237.         return(0);
  238.     }
  239.  
  240.     MultiXStart(MyId,"MultiX File Server",0,ApplEventHandler);
  241.  
  242.     printf("Type any key to stop the program...\n");
  243.  
  244.     while (    ApplShutdown    ==    False    )
  245.     {
  246.         MultiXWaitEvent();
  247.     }
  248.     return(0);
  249. }
  250.